package com.antis.olsl.data.allocate;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.antis.olsl.arouterlib.DataRoutePath;
import com.antis.olsl.base.BaseActivity;
import com.antis.olsl.data.adapter.DistributionInfoFiledListAdapter;
import com.antis.olsl.data.databinding.ActivityAllocateSlipGoodsDetailsBinding;
import com.antis.olsl.data.response.GetAllocateGoodsDetailsData;
import com.antis.olsl.library.bean.AllocateSlipInfo;
import com.antis.olsl.library.bean.GoodsFiledInfo;
import com.antis.olsl.library.utils.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.antis.olsl.activity.purchaseQuery
 * @ClassName: PurchaseSlipGoodsDetailsActivity
 * @Description: 配送单商品详情
 * @Author: 羊琪
 * @CreateDate: 2020/3/30 19:48
 * @UpdateDate: 2020/3/30 19:48
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Route(path = DataRoutePath.ACTIVITY_ALLOCATE_SLIP_GOODS_DETAIL)
public class AllocateSlipGoodsDetailsActivity extends BaseActivity<ActivityAllocateSlipGoodsDetailsBinding> {

    private ArrayList<GoodsFiledInfo> filedInfos = new ArrayList<>();
    private DistributionInfoFiledListAdapter adapter;
    private boolean fromSalesroom = false;
    private String productId;
    private String purchaseNumber;

    @Override
    protected ActivityAllocateSlipGoodsDetailsBinding getViewBinding() {
        return ActivityAllocateSlipGoodsDetailsBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @Override
    protected void initViews() {
        viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new DistributionInfoFiledListAdapter(filedInfos);
        viewBinding.recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() throws IllegalAccessException {
        getDetails();
    }

    /**
     * 获取商品详情
     */
    private void getDetails() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("allocateNumber", purchaseNumber);
        map.put("productId", productId);
        // okHttpClient.postJsonObjectParams(fromSalesroom ? UrlServerConnections.GET_GOODS_DETAILS_FOR_ALLOCATE_SLIP_BY_SALESROOM : UrlServerConnections.GET_GOODS_DETAILS_FOR_ALLOCATE_SLIP_BY_WAREHOUSE, map, GetAllocateGoodsDetailsRes.class);
    }

//    @Override
//    public void successResponse(BaseRes baseRes) {
//        if (baseRes instanceof GetAllocateGoodsDetailsRes) {
//            GetAllocateGoodsDetailsRes goodsDetailsRes = (GetAllocateGoodsDetailsRes) baseRes;
//            setData(goodsDetailsRes.getContent());
//        }
//    }

    private void setData(GetAllocateGoodsDetailsData detailsData) {
        if (detailsData == null) {
            return;
        }
        if (detailsData.getGoodsInfo() != null) {
            viewBinding.tvGoodsName.setText(detailsData.getGoodsInfo().getProductName());
            viewBinding.tvBarCode.setText(detailsData.getGoodsInfo().getBarCode());
            viewBinding.tvCommodityCode.setText(detailsData.getGoodsInfo().getProductCode());
            viewBinding.tvSpecificationOfGoods.setText(detailsData.getGoodsInfo().getSpecification());
        }

        if (detailsData.getAllocateInfo() != null) {
            AllocateSlipInfo slipInfo = detailsData.getAllocateInfo();
            filedInfos.add(new GoodsFiledInfo("调拨日期", slipInfo.getCreateTime()));
            filedInfos.add(new GoodsFiledInfo("调入" + (fromSalesroom ? "门店" : "仓库"), fromSalesroom ? slipInfo.getInSalesroomName() : slipInfo.getInWarehouseName()));
            filedInfos.add(new GoodsFiledInfo("调出" + (fromSalesroom ? "门店" : "仓库"), fromSalesroom ? slipInfo.getExSalesroomName() : slipInfo.getExWarehouseName()));
            filedInfos.add(new GoodsFiledInfo("调拨数量", StringUtils.getCommaFormat(new BigDecimal(slipInfo.getAllocateNum()))));
            filedInfos.add(new GoodsFiledInfo("实收调拨数量", StringUtils.getCommaFormat(new BigDecimal(slipInfo.getReceiveNum()))));
            filedInfos.add(new GoodsFiledInfo("调拨差异数量", StringUtils.getCommaFormat(new BigDecimal(slipInfo.getDifferentNum()))));
            filedInfos.add(new GoodsFiledInfo("调拨金额", StringUtils.getCommaFormat(BigDecimal.valueOf(slipInfo.getAllocatePrice())) + "元"));
        }
        adapter.setList(filedInfos);
    }
}
